package com.example;

import com.example.config.AppConfig;
import com.example.controller.BlogController;
import com.example.dao.BlogRepository;
import com.example.entity.Blog;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class MyApplication {
    public static void main(String[] args) {
        // XML-based Configuration Metadata
//        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("beans.xml");

        // Annotation-based Configuration Metadata
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(AppConfig.class);
        System.out.println("Application.main");
//        BlogController blogController = new BlogController(new SimpleBlogService(new NopeBlogRepository()));
        BlogController blogController = (BlogController) applicationContext.getBean("blogController");
        Blog blog = new Blog(1,"yi","111");
        blogController.save(blog);

        String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();
        for (String beanDefinitionName : beanDefinitionNames) {
            System.out.println(beanDefinitionName);
        }

        System.out.println("===== ===== =====");

        BlogRepository simpleBlogRepository = (BlogRepository) applicationContext.getBean("simpleBlogRepository");
        System.out.println(applicationContext.containsBean("simpleBlogRepository"));
    }
}
